from typing import List


class Solution:
    def minMoves2(self, nums: List[int]) -> int:
        nums.sort()
        ans = 0
        x = nums[len(nums) // 2]
       
        for n in nums:
            ans+=abs(n-x)
        return ans